﻿using System.Linq;

namespace TowerCraneMonitorClient.NetClient
{
    /// <summary>
    /// 发送报文
    /// </summary>
    public class Request
    {
        static string moniterId = null;
        readonly static object lockObject = new object();

        /// <summary>
        /// 监控设备黑匣子id
        /// </summary>
        public string Id { get => moniterId; }

        public Request()
        {
            if (moniterId == null)
            {
                lock (lockObject)
                {
                    if (moniterId == null)
                    {
                        using var db = new EntityContext();
                        moniterId = db.MoniterInfos.FirstOrDefault()?.Id;
                        if (moniterId == null) throw new MissMoniterIdException();
                    }
                }
            }
        }
    }
}
